package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ProductBean;
import com.project.mapper.IProductMapper;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements IProductService {
    @Autowired
    private IProductMapper mapper;
    @Override
    public IPage<ProductBean> findByItem(Integer pageNO, String name, Integer startNum, Integer endNum, String salePrice, String type) {
        QueryWrapper<ProductBean> qw = new QueryWrapper<>();
        if (name!=null&&name.length()!=0){
            qw.like("p_name",name);
        }
        if(startNum!=null){
            qw.ge("p_num",startNum);
        }
        if(endNum!=null){
            qw.le("p_num",endNum);
        }
        if (salePrice!=null&&salePrice.length()!=0){
            qw.like("p_sellPrice",salePrice);
        }
        if (type!=null&&type.length()!=0){
            qw.like("p_type",type);
        }
        return mapper.selectPage(new Page(pageNO,3),qw);

    }


    @Override
    public ProductBean findById(String id) {
        return mapper.selectById(id);
    }

    @Override
    public void updateSalePrice(String id, Integer price) {
        ProductBean productBean = mapper.selectById(id);
        productBean.setSellPrice(price);
        mapper.updateById(productBean);
    }
}
